#!/bin/sh

if [ -f 'conf.ini' ];then
    echo "Find an existing configuration file (conf.ini)"
else
    echo "[Database]\nDBFile= /work/db/cloudreve.db" > conf.ini
fi

if [ -f '/work/aria2/aria2.conf' ];then
    echo "Find an existing configuration file (aria2.conf)"
else
    echo "continue=true \nmin-split-size=10M \nenable-dht=true \ndht-file-path=/work/aria2/dht.dat \nbt-enable-lpd=true \nseed-time=0 \nbt-max-peers=100 \nmax-connection-per-server=13 \ndht-listen-port=6881-6999 \nenable-peer-exchange=true \nbt-tracker=udp://tracker.coppersurfer.tk:6969/announce,udp://tracker.leechers-paradise.org:6969/announce,udp://tracker.opentrackr.org:1337/announce,udp://p4p.arenabg.com:1337/announce,udp://9.rarbg.to:2710/announce,udp://9.rarbg.me:2710/announce,udp://tracker.openbittorrent.com:80/announce,udp://exodus.desync.com:6969/announce,udp://tracker.tiny-vps.com:6969/announce,udp://retracker.lanta-net.ru:2710/announce,udp://open.stealth.si:80/announce,udp://tracker.moeking.me:6969/announce,udp://denis.stalker.upeer.me:6969/announce,udp://tracker.torrent.eu.org:451/announce,udp://tracker.cyberia.is:6969/announce,udp://open.demonii.si:1337/announce,udp://ipv4.tracker.harry.lu:80/announce,udp://explodie.org:6969/announce,udp://xxxtor.com:2710/announce,udp://valakas.rollo.dnsabr.com:2710/announce \nenable-rpc=true \nrpc-allow-origin-all=true \nrpc-listen-all=true \nrpc-listen-port=6800 \nrpc-secret=vMBPoe6Ui2gV0fqx \nlisten-port=51413" > /work/aria2/aria2.conf
fi

chmod +x cloudreve

echo "Cloudreve config:"
cat conf.ini
echo "Aria2 config:"
cat /work/aria2/aria2.conf

nohup aria2c --conf /work/aria2/aria2.conf 2>&1 &
./cloudreve -c conf.ini